#include"queue.hpp"
#include<iostream>
//------------------------------------------
//function about listdata     --------------
//------------------------------------------

void ListData::init()
{
    std::cin>>a;
    std::cin>>b;
}

bool ListData::operator==(ListData& comData)
{
   if(this->a==comData.a&&this->b==comData.b)
   { 
        return 1;
   }
   else {
   return 0;
   }
}

void ListData::operator=(ListData* data)
{
   this->a=data->a;
   this->b=data->b;
}


void ListData::show()
{

    std::cout<<a<<" "<<b<<"\n";
}



//------------------------------------------
//function about LinkedQueue----------------
//------------------------------------------
LinkedQueue_Node::LinkedQueue_Node()
:next(nullptr)
{}

LinkedQueue::LinkedQueue()
:rear(this)
{}


void LinkedQueue::Clear()
{
 if(length>0)
 {
  LinkedQueue_Node* tmp1=this->next;
  LinkedQueue_Node* tmp2=this->next;
  while(tmp1!=this->rear)
  { 
     tmp2=tmp1->next;
     delete tmp1;
     tmp1=tmp2;
  }
  delete this->rear;
 }
 else
 {
    std::cout<<"already empty!\n";
 }
}


int LinkedQueue::GetLength()
{
   return length;
}


ListData LinkedQueue::GetHead()
{
 if(length>0)
 {
  return *(this->next->data);
 }
 else {
  std::cout<<"error!empty queue!\n";
 }
}


void LinkedQueue::QueueIn(ListData& a)
{
  LinkedQueue_Node* newNode=new LinkedQueue_Node;
  newNode->data=&a;
  this->rear->next=newNode;
  this->rear=newNode;
  length++;
}



void LinkedQueue::QueueOut()
{
   LinkedQueue_Node* tmp;
   tmp=this->next;
   this->next=this->next->next;
   delete tmp;

   length--;
}


LinkedQueue::~LinkedQueue()
{
  LinkedQueue::Clear();
}  
